package com.report.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.report.dto.request.ReportFileReq;
import com.report.dto.response.ReportFileRes;
import com.report.dto.response.SysReportFileRes;
import com.report.entity.SpecialReport;
import com.report.service.IReportFileService;
import com.report.service.SpecialReportService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author summer
 * @since 2024/06/25 14:54:57
 * 专题
 */
@RestController
@RequestMapping("/special")
@Slf4j
@AllArgsConstructor
public class ReportFileController  implements BaseCommonInterface<ReportFileReq, SysReportFileRes> {

   private final IReportFileService reportFileService;

    @Override
    public Result<String> save(@Valid ReportFileReq reportFileReq) {
        log.info("reportFileReq:{}", reportFileReq);
         reportFileService.saveReportFile(reportFileReq);
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        reportFileService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<SysReportFileRes>> lists(ReportFileReq reportFileReq) {
        Page<SysReportFileRes> page=reportFileService.lists(reportFileReq);
        return Result.successResult(page);
    }

    private SpecialReportService specialReportService;


    @Override
    public Result<SysReportFileRes> findById(Integer id) {
        SysReportFileRes reportFileRes=reportFileService.findById(id);
        LambdaQueryWrapper<SpecialReport> eq = Wrappers.lambdaQuery(SpecialReport.class).eq(SpecialReport::getSpecialId, id).select(SpecialReport::getReportId);
        List<Integer> reportIds = specialReportService.list(eq).stream().map(specialReport -> specialReport.getReportId()).collect(Collectors.toList());
        reportFileRes.setReportIds(reportIds);
        return Result.successResult(reportFileRes);
    }

    @Override
    public Result<String> batchDel(List<SysReportFileRes> list) {
        return null;
    }
}
